﻿@model App.Web.ViewModels.CompanyViewModel
           
@using App.Web.Utility;
@using App.Core.Extensions;

@{
    if (ViewBag.IsRegistrationMode == null)
    {
        Layout = "~/Views/Shared/_LayoutPrivate.cshtml";
    }
    else
    {
        Layout = "~/Views/Shared/_Layout.cshtml";
    }

    String pageTitle = ViewBag.PageTitle;

    ViewBag.Title = Html.GetPageTitle(pageTitle);    
}
<div class="page-heading">
    <h1>@pageTitle</h1>
    <div>
        Manage your company profile information. This is very important to highlight your company.
    </div>
</div>
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
<div class="GroupBox">
@using (Html.BeginForm())
{    
    @Html.ValidationSummary()

    if (Model == null)
    {
        @: @Html.ErrorMessageBox("Sorry! Requested Company was not found for edit.")
    }
    else
    {
        if (ViewBag.ProfileSaved != null)
        {
            @: @Html.InfoMessageBox("Company Profile Saved Successfully.")
        }		
		@*<div class="GroupHeaderOverlay" style="width:140px;">Company Information</div>*@    

		@Html.HiddenFor(model => model.ID)
        		
		<div class="editor-label">
			@Html.LabelFor(model => model.Name)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Name)
			@Html.ValidationMessageFor(model => model.Name)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.Description)
		</div>
		<div class="editor-field">
			@Html.TextAreaFor(model => model.Description)
			@Html.ValidationMessageFor(model => model.Description)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.IndustryTypeID)
		</div>
		<div class="editor-field">   
            @Html.DropDownListFor(model => model.IndustryTypeID, BindSelectList.IndustryTypes())              
			@*@Html.EditorFor(model => model.IndustryTypeID)*@
			@Html.ValidationMessageFor(model => model.IndustryTypeID)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Alias)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Alias)
			@Html.ValidationMessageFor(model => model.Alias)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Slogan)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Slogan)
			@Html.ValidationMessageFor(model => model.Slogan)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Address)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Address)
			@Html.ValidationMessageFor(model => model.Address)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.CountryID)
		</div>
		<div class="editor-field">
            @Html.DropDownListFor(model => model.CountryID, BindSelectList.Countries())
			@*@Html.EditorFor(model => model.DistrictID)*@
			@Html.ValidationMessageFor(model => model.CountryID)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.DistrictID)
		</div>
		<div class="editor-field">
            @Html.DropDownListFor(model => model.DistrictID, BindSelectList.Districts(Model.CountryID))
			@*@Html.EditorFor(model => model.DistrictID)*@
			@Html.ValidationMessageFor(model => model.DistrictID)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Phone)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Phone)
			@Html.ValidationMessageFor(model => model.Phone)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Fax)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Fax)
			@Html.ValidationMessageFor(model => model.Fax)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Email)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Email)
			@Html.ValidationMessageFor(model => model.Email)
            @Html.InfoMessageBox("Only use company email, not your personal email.")
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Web)
		</div>
		<div class="editor-field">
			@Html.EditorFor(model => model.Web)
			@Html.ValidationMessageFor(model => model.Web)
		</div>
if (ViewBag.IsRegistrationMode == null)
{
    String logoUrl = ImageManager.GetCompanyLogoUrl(Model.LogoFile, Model.ID);
    //String jsOnClick = String.Format("ShowCenteredPopUp('{0}', 'UploadImage', 1152, 600, true);", Url.Action("List", "CompanyLogo", new { ID = Model.ID }));
    String jsOnClick = "ShowLogoEditDialog();";
    String altText = Model.LogoFile.IsNullOrEmpty() ? "Add New Logo" : String.Format("{0} Logo", Model.Name);
		
		<div class="editor-field">
            @Html.HiddenFor(model => model.LogoFile)
            <a href="javascript:void(0);" onclick="@jsOnClick">Manage Company Logo</a>
            <div class="company-logo" style="margin-top:5px;">            
                <img id="imgCompanyLogo" src="@logoUrl" alt="@altText" title="@altText" onclick="@jsOnClick" style="cursor:pointer;" />
            </div>
		</div>
}   
		<div class="editor-label">
			@Html.LabelFor(model => model.Rating)
		</div>
		<div class="editor-field">
            @Model.Rating
            @Html.HiddenFor(model => model.Rating)
			@*@Html.EditorFor(model => model.Rating)*@
			@Html.ValidationMessageFor(model => model.Rating)
		</div>		
		@*<div class="editor-label">
			@Html.LabelFor(model => model.IsActive)
		</div>
		<div class="editor-field">            
			@Html.CheckBoxFor(model => model.IsActive)
			@Html.ValidationMessageFor(model => model.IsActive)
		</div>*@
		<div>
			<input type="submit" value="Save" />                
		</div>
    
		<div id="divLogoEditDialog" style="width:960px; height:560px;">
            <iframe id="iframeImageList" scrolling="no" frameborder="0" src="" style="width:100%;"></iframe>
        </div>
    
    <script language="javascript" type="text/javascript">
        var _LogoDialog = null;
        $(document).ready(function () {
            $('#CountryID').change(function () {
                Ajax('@Url.Action("GetDistrictsByCountry", "Home", new { area = AppConstants.Area.PUBLIC })'
                    , 'countryID=' + $(this).val()
                    , BindDistricts_Complete);
            });
            _LogoDialog = $('#divLogoEditDialog').dialog({
                autoOpen: false,
                title: 'Manage Company Logo',
                modal: true,
                width: $('#divLogoEditDialog').width(),
                height: $('#divLogoEditDialog').height()
            });
        });
        function BindDistricts_Complete(result) {
            var types = eval(result);
            var ddl = $('#DistrictID');
            $(ddl).html('');
            $(ddl).append($("<option></option>").attr("value", '0').text('Please Select'));
            if (types != null && types.length > 0) {
                for (i = 0; i < types.length; i++) {
                    var type = types[i];
                    $(ddl).append($("<option></option>").attr("value", type.ID).text(type.Name));
                }
            }
        }
        function AdjustiFrameHeight(height) {
            $('#iframeImageList').height(height);
        }
        function ChildHideLoading(){            
            HideLoadingAnimation();
        }
        function ShowLogoEditDialog(){
            $(_LogoDialog).dialog('open');
            var iFrame = $(_LogoDialog).find('iframe');
            if($(iFrame).attr('src').length == 0){
                $(iFrame).attr('src', '@Url.Action("List", "CompanyLogo", new { ID = Model.ID })');
                ShowLoadingAnimation(false);          
            }  
        }
        function SetLogo(logoUrl){
            $('#imgCompanyLogo').attr('src', logoUrl);
        }
    </script>
    }
}
</div>
@*<div>
    @Html.ActionLink("Back to List", "Index")
</div>
*@
